//
//  DSZShopDetailViewController.m
//  7.13苏宁框架
//
//  Created by lovena on 15/7/20.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "DSZShopDetailViewController.h"
#import "DSZShopViewController.h"
#import "Common.h"
#import "ShopModel.h"
#import "ShopPayView.h"
#import "DSZMainViewController.h"
#import "DSZDiZhiGLViewController.h"
@interface DSZShopDetailViewController ()<ShopPayViewDelegate>
@property(nonatomic,retain)NSMutableArray *smodel;//数组
@property(nonatomic,retain)ShopPayView *footView;//段位视图
@end

@implementation DSZShopDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self clickBtn:_firBtn];
    self.title=@"订单详情";
    self.tjfield.delegate=self;
    self.gkfield.delegate=self;
    [self initNavBtn];
}
-(void)loadView
{
    [super loadView];
    //view
    UIView *view=[[UIView alloc]initWithFrame:self.view.bounds];
    view.backgroundColor=[UIColor cyanColor];
    [view addSubview:self.tableView];
    self.view=view;
    
    
    _footView=[ShopPayView createShopPay];
    _footView.frame=CGRectMake(0, 480-49, 320, 49);
    _footView.delegate=self;
    [view addSubview:_footView];
    
    self.tableView.showsVerticalScrollIndicator=NO;
    
}
-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;
    //隐藏分栏
    DSZMainViewController *main=(DSZMainViewController *)self.tabBarController;
    [main hiddenMainTabbar:YES];
}
//返回按钮
-(void)initNavBtn
{
    
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(0, 0, 30,25);
    [btn setBackgroundImage:[UIImage imageNamed:@"back_black_icon"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(returnView) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBtn=[[UIBarButtonItem alloc]initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem=leftBtn;
    
    [self loadDetail];
    
}
//返回按钮事件
-(void)returnView
{
    [self.navigationController popViewControllerAnimated:YES];
    DSZMainViewController *main=(DSZMainViewController *)self.tabBarController;
    [main hiddenMainTabbar:NO];
}
//选择按钮
- (IBAction)clickBtn:(UIButton *)sender {
    if (sender==_firBtn) {
        self.footImage.image=[UIImage imageNamed:@"pop-1"];
        _firBtn.titleLabel.font=[UIFont systemFontOfSize:16];
        _secBtn.font=[UIFont systemFontOfSize:15];
    }
    else
    {
        self.footImage.image=[UIImage imageNamed:@"pop"];
        _firBtn.font=[UIFont systemFontOfSize:15];
        _secBtn.font=[UIFont systemFontOfSize:16];
    }
}

//文本输入操作
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField endEditing:YES];
    return YES;
}
//去数据
-(NSMutableArray*)smodel
{
    if (_smodel==nil) {
        _smodel=[NSKeyedUnarchiver unarchiveObjectWithFile:FilePath];
        if (_smodel==nil) {
            _smodel=[NSMutableArray array];
        }
    }
    return _smodel;
}

-(void)loadDetail
{
    float allprice=0;
    //取出归档的数据
    for (ShopModel *shopmodel in self.smodel) {
        if (shopmodel.flag) {
            float str=[shopmodel.price floatValue];
            allprice+=str;
        }
    }
   
    _allPrice.text=[NSString stringWithFormat:@"¥%.2f",allprice];
   
    _allPrice2.text=_allPrice.text;
    float carr;
    if (allprice<69) {
        _carriage.text=@"+¥5.00";
        carr=5;
    }
    else
    {
        _carriage.text=@"+¥0.00";
        carr=0;
    }
     //总共需要付款
    _footView.allprice.text=[NSString stringWithFormat:@"%.2f",allprice+carr];
}


//点击某行
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    @synchronized(self)
    {
        if (indexPath.section==0&&indexPath.row==0) {
            DSZDiZhiGLViewController *dizhi=[[DSZDiZhiGLViewController alloc]init];
            [self.navigationController pushViewController:dizhi animated:YES];
        }
        if (indexPath.section==1&&indexPath.row==0) {
            
            UIActionSheet *sheet=[[UIActionSheet alloc]initWithTitle:nil delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"在线支付"otherButtonTitles:@"货到付款－－现金",@"货到付款－－刷卡",@"门店付款", nil];
            [sheet showInView:self.view];
        }
        if (indexPath.section==2&&indexPath.row==0) {
            UIActionSheet *sheet=[[UIActionSheet alloc]initWithTitle:nil delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"不开发票"otherButtonTitles:@"普通发票",@"电子发票", nil];
            [sheet showInView:self.view];
        }
 
    }
   }


-(void)PayClick
{
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"很遗憾" message:@"这其实从一开始就是一个骗局，你上当受骗了！！！" delegate:nil cancelButtonTitle:@"无奈" otherButtonTitles: nil];
    [alert show];
    
//    //清空所有购物车商品
//    NSMutableArray *array=[NSKeyedUnarchiver unarchiveObjectWithFile:FilePath];
//    [array removeAllObjects];
//    [NSKeyedArchiver archiveRootObject:array toFile:FilePath];
//    [self loadDetail];
}
@end
